<template>
	<view class="content" v-if="show==1">
		<view class="qiehuan">
		  <view @click="qiehuan" data-s="-1" :class="status==-1?'status active':'status'">领优惠券</view>
		  <view @click="qiehuan" data-s="0" :class="status==0?'status active':'status'">未使用</view>
		  <view @click="qiehuan" data-s="1" :class="status==1?'status active':'status'">已使用</view>
		  <view @click="qiehuan" data-s="2" :class="status==2?'status active':'status'">已过期</view>
		</view>
		<view class="yhq" v-for="(y,index) in yhq" v-if="status==-1">
		    <view class="yhq_l">
			  <image src="../../static/yhq_left.png" mode='scaleToFill'></image>
		      <view class="zhekou">{{zdtype==1?'㉿':'￥'}}{{y.money}}</view>
		    </view>
		    <view class="yhq_r">
		      <view class="tiaojian">满{{y.total}}可用<view :data-index="index" class="anniu2" @click="ling" >领取</view></view>
		      <view class="shijian">
		        <view class="time">
		        {{y.stime}}至{{y.etime}}可用
				
		        </view>
		      </view>
		    </view>
		</view>
		<view class="kong" v-if="!yhq[0] && status==-1">
			<image src="../../static/empty.png" mode="widthFix"/>
			<view>暂无可领取的优惠券</view>
		</view>
		
		<view class="yhq" v-for="(y,index) in youhuiquan" v-if="status>-1">
		    <view class="yhq_l">
			  <image src="../../static/yhq_left.png" mode='scaleToFill'></image>
		      <view class="zhekou">{{zdtype==1?'㉿':'￥'}}{{y.money}}</view>
		    </view>
		    <view class="yhq_r">
		      <view class="tiaojian">满{{y.total}}可用<view class="anniu2" @click="yong" v-if="status==0">使用</view></view>
		      <view class="shijian">
		        <view class="time">
		        {{y.stime}}至{{y.etime}}可用
				
		        </view>
		      </view>
		    </view>
			<image src="../../static/shixiao.png" v-if="y.status==2" mode="aspectFit" class="zhuang"/>
			<image src="../../static/yiyong.png" v-if="y.status==1" mode="aspectFit" class="zhuang"/>
		</view>
		<view class="kong" v-if="!youhuiquan[0] && status>-1">
			<image src="../../static/empty.png" mode="widthFix"/>
			<view>暂无优惠券信息</view>
		</view>
	</view>
</template>

<script>
	var app=getApp();
	export default {
		data() {
			return {
				uid: 0,
				status:-1,
				show:0,
				empty:0,
				zdtype:0,
				yhq:[],
				youhuiquan:[]
			}
		},
		onLoad() {
			const uid = uni.getStorageSync('uid');
			if(app.isBlank(uid)==true){
				app.error_msg("请先登录");
			}
			var that=this;
			//#ifdef APP-PLUS
			uni.getSystemInfo({
			    success: function (res) {
					if(res.platform=='ios'){
						//that.zdtype=1;
					}
			    }
			});
			//#endif
			this.uid=uid;
			this.getdata2();
		},
		methods: {
			getdata(){
				var that=this;
				uni.showLoading({
				    title: '数据加载中'
				});
				uni.request({
				    url: app.globalData.url+"user/yhq",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:that.uid,status:that.status},
				    success: (res) => {
						uni.hideLoading();
						that.youhuiquan=res.data.data.yhq
						that.show=1;
				    }
				});
			},
			getdata2(){
				var that=this;
				uni.showLoading({
				    title: '数据加载中'
				});
				uni.request({
				    url: app.globalData.url+"index/yhq",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:that.uid},
				    success: (res) => {
						uni.hideLoading();
						that.yhq=res.data.data.yhq
						that.show=1;
				    }
				});
			},
			qiehuan(e){
				var s=e.currentTarget.dataset.s;
				this.status=s;
				if(s==-1){
					this.getdata2();	
				}else{
					this.getdata();
				}
				
			},
			ling(e){
				var index=e.currentTarget.dataset.index;
				var id=this.yhq[index].id
				var that=this;
				uni.showLoading({
				    title: '领取中'
				});
				uni.request({
				    url: app.globalData.url+"index/lqyhq",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:that.uid,id:id},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							uni.showToast({
							    title: res.data.msg,
								icon:'none',
							    duration: 1500
							});
							return false;
						}
						uni.showToast({
						    title: res.data.msg,
						    duration: 1000
						});
						that.yhq.splice(index,1);
						
				    }
				});
			},
			yong(){
				uni.reLaunch({
				    url: '/pages/goods/index'
				});
			}
		}
	}
</script>

<style>
	.zhuang{width:60px;height:60px;position: absolute;right: 10px;z-index: 9999;}
	.kong view{text-align: center;color:#999;margin-top: 5px;}
	.kong image{width:100px;}
	.kong{width:100%;margin-top: 30%;text-align: center;}
	page{background-color: rgb(245, 245, 245);}
	.qiehuan{width:100%;height:50px;background-color: #fff;overflow: hidden;}
	.status{width:25%;float: left;line-height: 50px;font-size: 0.9rem;color:#666;text-align: center;}
	.active{color:#05c160!important;}
	.yhq{width:94%;margin: 0px 3%;overflow: hidden;padding-top: 13px;position: relative;}
	.yhq_l{width:30%;float: left;height:70px;overflow: hidden;position: relative;}
	.yhq_l image{width:100%;height:70px;}
	.zhekou{width:100%;height:70px;position: absolute;top:0px;text-align: center;line-height: 70px;color:#fff;font-size: 1.1rem;}
	.yhq_r{width:70%;float: left;height:70px;background-color: #fff;}
	.tiaojian{width:94%;margin: 0px 3%;height:39px;line-height: 39px;color:#666;border-bottom: 1px rgb(245, 245, 245) solid;}
	.shijian{width:94%;margin: 0px 3%;height:30px;overflow: hidden;}
	.time{width:100%;float: left;height:30px;line-height: 30px;overflow: hidden;color:#999;font-size: 0.6rem;position: relative;}
	.anniu{width:50px;height:22px;line-height: 22px;background-color: #05c160;text-align: center;color:#fff;font-size: 0.7rem;position: absolute;right:0px;top:4px;border-radius: 20px;}
	.hover{background-color: #9e9d9e!important;}
	.bottom{width:100%;height:40px;}
	.anniu2{width:50px;height:22px;line-height: 22px;background-color: #05c160;text-align: center;color:#fff;font-size: 0.7rem;border-radius: 20px;float: right;margin-top: 9px;}
</style>
